package com.lopo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.beust.jcommander.internal.Lists;
import lombok.Data;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author hgh
 * @since 2020-05-13 15:14
 */
public class KK {

    public static void main(String[] args) throws InterruptedException {
        final List<User> list = new ArrayList<>();
        list.add(new User(1, DateUtil.parse("2022-08-24 18:36:08", "yyyy-MM-dd HH:mm:ss")));
        list.add(new User(2, DateUtil.parse("2022-08-24 18:36:08", "yyyy-MM-dd HH:mm:ss")));
        list.add(new User(3, DateUtil.parse("2022-08-25 18:36:08", "yyyy-MM-dd HH:mm:ss")));
        list.add(new User(4, DateUtil.parse("2022-08-26 18:36:08", "yyyy-MM-dd HH:mm:ss")));
        list.add(new User(5, DateUtil.parse("2022-08-27 18:36:08", "yyyy-MM-dd HH:mm:ss")));

        final List<UserVO> collect = Optional.ofNullable(list).orElse(new ArrayList<>()).stream()
            .collect(Collectors.groupingBy(k -> DateUtil.format(k.getDate(), "yyyy-MM-dd")))
            .entrySet().stream().map(e -> new UserVO(e.getKey(), e.getValue())).collect(Collectors.toList());

        System.out.println("collect = " + collect);


    }


}

@Data
class UserVO{
    private String group;
    private List<User> list;

    public UserVO(String group, List<User> list) {
        this.group = group;
        this.list = list;
    }
}

@Data
class User{
    private Integer id;
    private Date date;

    public User(Integer id, Date date) {
        this.id = id;
        this.date = date;
    }
}